package fr.jee.ejb.model;

import java.io.Serializable;
import java.lang.String;
import java.util.List;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

@Entity
@Table(name = "role")
public class Role implements Serializable {

	@Id
	@Column(name = "code", length = 50)
	private String code;

	@Size(max = 100)
	@NotNull
	@Column(name = "libelle", length = 100, nullable = false)
	private String libelle;

	@Size(max = 255)
	@Column(name = "description", length = 255, nullable = true)
	private String description;

	@ManyToMany(mappedBy = "listeRole", cascade = CascadeType.REFRESH)
	private List<Profil> listeProfil;

	public Role() {
		super();
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getLibelle() {
		return this.libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Profil> getListeProfil() {
		return listeProfil;
	}

	public void setListeProfil(List<Profil> listeProfil) {
		this.listeProfil = listeProfil;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		Role other = (Role) obj;
		return new EqualsBuilder().append(code, other.code).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(code).toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("code", code).toString();
	}

}
